import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import {PageParamsModel} from "../../../model/common/page-params.model";

@Injectable()
export class ClientBirthdayProvider {
    prePath: string;

    constructor(public http: HttpClient) {
        this.prePath = 'party/v1';
    }

    /**
     * 获取生日客户
     * @param {number} type
     * @param {number} notLoading
     * @param {PageParamsModel} pageModel
     * @returns {Observable<any>}
     */
    getBirthdayList(type: number, notLoading, pageModel: PageParamsModel,notLoadingNow=0,): Observable<any> {
        const p = `birthClient`;
        const url = `/${this.prePath}/${p}`;
        return this.http.get(url, {
            params: {
                'not-loading': '' + notLoading,
                'not-loading-now':''+ notLoadingNow,
                type: '' + type,
                pageNum: '' + pageModel.pageNum,
                pageSize: '' + pageModel.pageSize
            }
        });
    }

    momentOperate(moment) {
        const month = moment.month();
        const date = moment.date();
        return {
            moment,
            monthDescribe: month ? `${month}月` : '',
            dateDescribe: date ? `${date}天` : '',
            toString: function () {
                return `${this.monthDescribe}${this.dateDescribe}`;
            }
        }
    }

    /**
     * 过滤为空的电话号码
     * @param clientList
     */
    checkMobileNull(clientList){
        clientList.forEach(client => {
            const mobileList = [];
            if(client.mobilePhone && client.mobilePhone.length){
                client.mobilePhone.forEach(mobile => {
                    if(mobile && mobile.mobile){
                        mobileList.push({
                            id:mobile.id,
                            mobile:mobile.mobile
                        });
                    }
                });
            }
            client.mobilePhone = mobileList;
        });
        return clientList;
    }
}
